import type { UserIndividualType } from "@/types/userlnfo";
import { getLocalToken, removeLocalToken, setLocalToken } from "@/utils/auth";
import { defineStore } from "pinia";
import { ref } from "vue";


export const useUserStore = defineStore('geek-user', () => {
  //token 信息
  const token = ref(getLocalToken() || '')

  //登录成功，保存token
  const setToken = (val: string) => {
    token.value = val
    setLocalToken(val)
  }

  //退出登录，删除token
  const clearToken = () => {
    token.value = ''
    removeLocalToken()
  }

  // 个人信息
  const individual = ref<UserIndividualType>()
  // 设置个人信息
const setIndividual = (data: UserIndividualType) => {
    individual.value = data
  }

  //记得返回
  return {
    token,
    setToken,
    clearToken,
    setIndividual,
    individual
  }
})
